var order_index = new Vue({
	el: "#app",
	data: {
		type: 0,
		orders: [],
		page: 1,
		isExcute: false,
		isBottom: false,
		empty: true
	},
	methods: {
		toType: function(type) {
			if (type == this.type) {
				return;
			}
			Jump.to(page.order.index, "type=" + type);
		},
		getOrder: function() {
			wx.showLoading({
				title: "加载中..."
			});
			this.$http.post(baseUrl + "order/list", {
				currentPage: this.page,
				pageSize: 10,
				status: this.type,
			}).then(function(d) {
				wx.hideLoading();
				this.empty = false;
				var a = d.data;
				if (!a.success) {
					wx.showToast({
						title: a.description,
						icon: "none",
						duration: 2e3,
						mask: !1
					});
				} else {
					var s = this;
					if (0 == a.data.length && s.page > 1) {
						s.isBottom = true;
						wx.showToast({
							title: "已经到最底下了",
							icon: "none",
							duration: 1e3,
							mask: !0
						});
					} else if (a.data.length > 0 && 1 == s.page) {
						a.data.forEach(function(e) {
							s.orders.push(e);
						});
					} else if (0 == a.data.length && 1 == s.page) {
						s.empty = true;
					} else {
						a.data.forEach(function(e) {
							s.orders.push(e);
						});
					}
				}
				this.isExcute = false;
			}).catch(function(error) {
				this.isExcute = false;
				wx.hideLoading();
				console.error(error);
				wx.showToast({
					title: "网络错误，请稍后重试",
					icon: "none",
					duration: 2e3,
					mask: !1
				});
			});
		},
		handleScroll: function() {
			// 防止重复
			if (this.isExcute) {
				return;
			}
			if (this.isBottom) {
				return;
			}
			var flag = srollEvent.isReachBottom();
			if (!flag) {
				return;
			}
			this.isExcute = true;
			this.page++;
			this.getOrder();
		},
		cancel: function(order) {
			var s = this;
			wx.showModal({
				title: "取消订单",
				content: "确定取消订单？",
				confirm: function() {
					wx.showLoading({
						title: "加载中..."
					});
					s.$http.post(baseUrl + "order/delete", {
						orderNo: order.orderNo
					}).then(function(t) {
						var s = t.data;
						wx.hideLoading(), s.success ? (wx.showToast({
							title: "删除订单成功",
							icon: "none",
							duration: 2e3,
							mask: !1
						}), setTimeout(function() {
							order_index.page = 1, order_index.getOrder();
						}, 1e3)) : wx.showToast({
							title: s.description,
							icon: "none",
							duration: 2e3,
							mask: !1
						});
					}).catch(function(t) {
						wx.hideLoading(), wx.showToast({
							title: "网络错误，请稍后重试",
							icon: "none",
							duration: 2e3,
							mask: !1
						});
					});
				}
			});
		},
		toDetail:function(item){
			Jump.to(page.order.detail,"orderNo="+item.orderNo);
		},
		receive: function(order) {
			var t = this;
			wx.showModal({
				title: "确认收货",
				content: "亲！确认收货？",
				confirm: function() {
					wx.showLoading({
						title: "加载中...",
						mask: !0
					});
					t.$http.post(baseUrl + "order/receive", {
						orderNo: order.orderNo
					}).then(function(t) {
						var a = t.data;
						wx.hideLoading(), a.success ? (wx.showToast({
							title: "确认收货成功",
							icon: "none",
							duration: 2e3,
							mask: !1
						}), setTimeout(function() {
							t.getOrder();
						}, 1e3)) : wx.showToast({
							title: a.description,
							icon: "none",
							duration: 2e3,
							mask: !1
						});
					}).catch(function(t) {
						wx.hideLoading(), wx.showToast({
							title: "网络错误，请稍后重试",
							icon: "none",
							duration: 2e3,
							mask: !1
						});
					});
				},
			});
		},
		pay:function(order){
			/* Jump.to(page.pay.type,"orderNo="+order.orderNo); */
			wx.showLoading({title:"支付中..."});
			this.$http.post(baseUrl+"order/pay/appWx",{
				orderNo:order.orderNo
			}).then(function(e){
				wx.hideLoading();
				var r = e.data;
				if(!r.success){
					 wx.showToast({
						title: r.description,
						icon: "none",
						duration: 2e3,
						mask: !0
					});
				}else{
					plus.webview.create(r.data, 'prod_pay_url2', {additionalHttpHeaders:{Referer:'https://app.meijiangzi.com/'}});
					Jump.to(page.pay.result, 'orderNo='+order.orderNo+'&orderType=mjz');
					// window.location.href=r.data;
				}
			})
		}
	},
	mounted: function() {
		window.addEventListener("scroll", this.handleScroll, {
			passive: false
		});
	},
	created: function() {
		login._2page(page.order.index, "type=0");
		var type = URLParam.get("type");
		this.type = type;
		this.getOrder();
		this.openid= localStorage.getItem("open_id");
	}
});
